* Set current directory and open log
cd "E:\Seagate Sync\VOL\My Documents\Research\Current projects\prlx\Posted\101113 EUP publication\Data analysis"
capture log close
log using "prlx-v01-analysis01", replace text


************************************************************************************
* Figures and tables for paper section "EU policy-making: A quantitative assessment"
************************************************************************************


* Project and author information
********************************
* Project:		prlx
* Programme:	prlx-v01-analysis01.do
* Date:			20 November 2010
* Author:		Frank Haege, University of Limerick
* Contact:		frank.haege@ul.ie 

* Do-file description
*********************
* This do-file generates the figures and tables presented and referred to in the section
* "EU policy-making: A quantitative assessment". It relies on the variables
* created by the do-file "prlx-v01-management02.do".


* Clear memory  
**************
version 11.0
clear all
macro drop _all
set more off

* Load dataset with type of instrument and type of legislative procedure variables
use "prlx-v01-management02.dta", clear
des, short


* Figure 1: Number of documents by type of file
***********************************************

* Calculate proportions of different types of files
generate ones = 1
egen instones = sum(ones), by(instrument)
generate instprop = instones/_N

* Generate new instrument variable with small categories merged into 'Other' category
generate instrumentp = instrument
replace instrumentp = 35 if instprop < 0.01
label val instrumentp instrumentl
tab instrument, sort m
tab instrumentp, sort m

* Plot number of documents by type of file
graph dot (sum) ones, over(instrumentp, sort(1) descending) /*
	*/ ytitle("Number of Documents", margin(medsmall)) /*
	*/ marker(1, mcolor(white)) scale(1.1)
	
	
* Table SI-1: Number of documents by type of file
*************************************************

* Tabulate instrument variable
tab instrument, sort m
	
	
* Figure 2: Number of proposals by type of legislative procedure
****************************************************************	

* Calculate proportions of types of legislative procedures
egen procones = sum(ones), by(procedurec)
egen nonmiss = sum(ones) if procedurec != 0
generate procprop = procones/nonmiss if procedurec != 0 

* Generate new procedure variable with small categories merged into "Other"
generate procedurecp = procedurec if procedurec != 0
replace procedurecp = 10 if procprop < 0.01 & procedurec != 0
label val procedurecp procedurel
tab procedurecp if procedurec != 0, m sort

* Plot number of proposals by type of legislative procedure
graph dot (sum) ones if procedurec != 0 /*
	*/ , over(procedurecp, sort(1) descending) /*
	*/ ytitle("Number of Proposals", margin(medsmall)) /*
	*/ marker(1, mcolor(white)) scale(1.1) xsize(4)
	
	
* Table SI-2.1: Number of proposals by type of legislative procedure
********************************************************************

* Tabulate procedure variable
tab procedurec if procedurec != 0, m sort


* Table SI-2.2: Number of proposals by type of legislative procedure (including "no procedure")
***********************************************************************************************

* Tabulate procedure variable
tab procedurec, m sort


* Table SI-3: Number of non-legislative documents by type of file, 1976-2009
****************************************************************************

* Check missing instrument values
tab instrument procedurec, m
list webno title if instrument == .	
* None of the observations with missing instrument values was subject to a legislative procedure

* Label year variable
label var year "Year"

* Tabulate the number of non-legislative documents by type of file
tab year instrument if instrument == 4 | instrument == 22 | instrument == 23


* Table SI-4: Number of legislative proposals by type of file, 1976-2009
************************************************************************

* Tabulate the number of legislative proposals by type of file
tab year instrument if procedurec == 1 | procedurec == 2 | procedurec == 3


* Generate Table SI-5 Number of legislative proposals by type of procedure, 1976-2009
*************************************************************************************

* Tabulate the number of legislative proposals by type of procedure
tab year procedurec if procedurec < 4 & procedurec != 0


* Collapse dataset to generate the remaining graphs
***************************************************

* Generate instrument dummy variables
tab instrument, m gen(inst_)

* Generate instrument dummy variables for legislative acts decided through main three procedures
* Decisions
generate inst_1c = 0
replace inst_1c = 1 if inst_1 == 1 & (procedurec == 1 | procedurec == 2 | procedurec == 3)
* Regulations
generate inst_2c = 0
replace inst_2c = 1 if inst_2 == 1 & (procedurec == 1 | procedurec == 2 | procedurec == 3)
* Directives
generate inst_3c = 0
replace inst_3c = 1 if inst_3 == 1 & (procedurec == 1 | procedurec == 2 | procedurec == 3)

* Generate procedure dummy variable
tab procedurec, m gen(proc_)

* Collapse dataset by year
collapse (sum) inst_* proc_*, by(year)

* Label new variables
label var inst_23 "Communications"
label var inst_4 "Reports"
label var inst_22 "Working papers"
label var inst_1c "Decisions"
label var inst_2c "Regulations"
label var inst_3c "Directives"
label var proc_2 "Consultation"
label var proc_3 "Cooperation"
label var proc_4 "Codecision"


* Figure 3: Number of non-legislative documents by type of file, 1976-2009
**************************************************************************

* Replace zeros for number of working papers before 1996 by missing values
list year inst_23 inst_4 inst_22
replace inst_22 = . if year < 1996	

* Check that Figure 3 is based on numbers given in Table SI-3
list year inst_23 inst_4 inst_22

* Plot the number of non-legislative documents by type of file
twoway line inst_23 inst_4 inst_22 year, /*
	*/ xlabel(1975 1980:2010) ylabel(0 50:250) xscale(range(1975 2010)) /*
	*/ ytitle("Number of documents") /*
	*/ lpattern("-..."l  _) lcolor(white white white) /*
	*/ legend(cols(3) region(lcolor(none)))

	
* Figure 4: Number of legislative proposals by type of file, 1976-2009
**********************************************************************

* Check that Figures 4, SI-4.1, and SI-4.2 are based on the numbers given in Table SI-4
list year inst_1c inst_2c inst_3c

* Plot the number of legislative proposals by type of file
twoway line inst_1c inst_2c inst_3c year, /*
	*/ xlabel(1975 1980:2010) ylabel(0 50:250) xscale(range(1975 2010)) /*
	*/ ytitle("Number of proposals") /*
	*/ lpattern("-..." _ l) lcolor(white white white) /*
	*/ legend(cols(3) region(lcolor(none)))
	
	
* Figure SI-4.1: Number of proposals for decisions, 1976-2009
*************************************************************

* Plot number of proposals for decisions over time
twoway line inst_1c year, ylabel(0 20:120) xlabel(1975 1980:2010) lcolor(white)


* Figure SI-4.2: Number of proposals for directives, 1976-2009
**************************************************************

* Summary statistics for yearly number of proposals for directives
sum inst_3c, d

* Plot number of proposals for directives over time
twoway line inst_3c year, ylabel(0 20:100) xlabel(1975 1980:2010) lcolor(white)


* Figure 5: Number of legislative proposals by type of procedure, 1976-2009
***************************************************************************
 
* Replace zeroes of cooperation variable before 1987 by missing values 
list year proc_2 proc_3 proc_4
replace proc_3 = . if year < 1987

* Replace zeroes of codecision variable before 1993 by missing values
replace proc_4 = . if year < 1993
list year proc_2 proc_3 proc_4
	
* Check that Figure 5 is based on numbers given in Table SI-5
list year proc_2 proc_3 proc_4

* Plot number of legislative proposals by type of procedure
twoway line proc_2 proc_3 proc_4 year, /*
	*/ xlabel(1975 1980:2010) ylabel(0 50:300) xscale(range(1975 2010)) /*
	*/ ytitle("Number of proposals") /*
	*/ lpattern(_ "-..." l) lcolor(white white white) /*
	*/ legend(cols(3) region(lcolor(none)))

	
* Exit do-file
log close
exit
